import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonalSettingPage(Base):
    """
    账户设置页
    """

    # TODO: 修改密码及进入管理和切换账号,注销后的页面未遍历

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.setting_home_btn = (By.XPATH, Personal.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.setting_back_btn = (By.XPATH, Personal.RESOURCE_ID.format('ivBack'))

        # 页面_变量名_元素类型
        # 用户头像
        self.setting_user_cover_img = (By.XPATH, Personal.RESOURCE_ID.format("iv_user_avatar"))

        # 用户性别
        self.setting_user_gender_icon = (By.XPATH, Personal.RESOURCE_ID.format("iv_user_gender"))

        # 账户名称
        self.setting_user_name_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_user_name"))

        # 切换账号按钮
        self.setting_change_user_btn = (By.XPATH, Page.TEXT.format("切换账号"))

        # 注销按钮
        self.setting_logout_user_btn = (By.XPATH, Personal.RESOURCE_ID.format("bt_delete_user"))
        # self.setting_logout_user_btn = (By.XPATH, Page.TEXT.format("注销"))

        # 密码管理标题
        self.setting_password_title_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_password_manager_text"))

        # 密码管理文案
        # self.setting_password_management_text = (By.XPATH, Page.TEXT.format("　　为了保证您的隐私，使用车信，mark...等功能时需要输入密码才可以使用"))
        self.setting_password_management_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_password_manager_desc"))

        # 修改密码按钮
        # self.setting_change_user_password_btn = (By.XPATH, Page.TEXT.format("修改密码"))
        self.setting_change_user_password_btn = (By.XPATH, Personal.RESOURCE_ID.format("modify_password_bt"))

        # 钥匙管理标题
        self.setting_key_title_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_key_manager_text"))

        # 钥匙管理文案
        self.setting_key_management_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_key_manager_desc"))
        # self.setting_key_management_text = (By.XPATH, Page.TEXT.format("　　可对钥匙进行管理，如用户使用绑定钥匙打开车门可直接登录系统。"))

        # 进入管理按钮
        # self.setting_access_management_btn = (By.XPATH, Page.TEXT.format("进入管理"))
        self.setting_access_management_btn = (By.XPATH, Personal.RESOURCE_ID.format("enter_key_manger_bt"))

    # get/click/input
    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.setting_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.setting_back_btn)

    def get_user_cover(self):
        """
        获取用户头像

        :return: 元素对象
        """
        return self.find_element_o(self.setting_user_cover_img)

    def get_user_gender(self):
        """
        获取用户性别

        :return: 元素对象
        """
        return self.find_element_o(self.setting_user_gender_icon)

    def get_user_name(self):
        """
        获取用户名称

        :return: 元素对象
        """
        return self.find_element_o(self.setting_user_name_text)

    def click_change_user(self):
        """
        点击切换账号按钮

        :return: None
        """
        self.click_element(self.setting_change_user_btn)

    def click_logout_user(self):
        """
        点击注销按钮

        :return: None
        """
        self.click_element(self.setting_logout_user_btn)

    def get_password_title(self):
        """
        密码管理标题

        :return: 元素对象
        """
        return self.find_element_o(self.setting_password_title_text)

    def get_password_management(self):
        """
        获取密码管理文案

        :return: 元素对象
        """
        return self.find_element_o(self.setting_password_management_text)

    def click_change_user_password(self):
        """
        点击修改密码按钮

        :return:None
        """
        self.click_element(self.setting_change_user_password_btn)

    def get_key_title(self):
        """
        获取钥匙管理标题

        :return:元素对象
        """
        return self.find_element_o(self.setting_key_title_text)

    def get_key_management(self):
        """
        获取钥匙管理文案

        :return: 元素对象
        """
        return self.find_element_o(self.setting_key_management_text)

    def click_access_management(self):
        """
        点击进入管理按钮

        :return: None
        """
        self.click_element(self.setting_access_management_btn)

    def is_display_personal_setting(self):
        """
        是否进入车辆管理界面

        :return: bool
        """
        return self.is_display(self.setting_user_cover_img)
